//
//  HMSelectTitleBtn.m
//  HMMarket
//
//  Created by maimaigo3 on 2017/5/25.
//  Copyright © 2017年 homai. All rights reserved.
//

#import "HMSelectTitleBtn.h"

@implementation HMSelectTitleBtn

- (instancetype)initWithFrame:(CGRect)frame HomeCategory:(HomeCategoryDetail *)cate {
    self = [super init];
    if (self) {
        self.frame = frame;
        self.cate = cate;
        UIImageView *titleImage = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 30) / 2 , 0, 30, 40)];
        titleImage.contentMode = UIViewContentModeScaleAspectFit;
        [titleImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kImageUrl,cate.pic]]];
        [self addSubview:titleImage];
        
        UILabel *clickBtn = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleImage.frame) + 9, frame.size.width, 25)];
        clickBtn.textAlignment = NSTextAlignmentCenter;
        clickBtn.font = [UIFont systemFontOfSize:15.0f];
        clickBtn.text = cate.cat_name;
        [self addSubview:clickBtn];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCover:)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame imageURL:(NSString *)imageURL title:(NSString *)title {
    self = [super init];
    if (self) {
        self.frame = frame;
        UIImageView *titleImage = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) / 2 , 5, 40, 30)];
        titleImage.image = [UIImage imageNamed:imageURL];
        [self addSubview:titleImage];
        
        
        UILabel *clickBtn = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleImage.frame) + 9 + 5, frame.size.width, 25)];
        clickBtn.textAlignment = NSTextAlignmentCenter;
        clickBtn.font = [UIFont systemFontOfSize:15.0f];
        clickBtn.text = title;
        [self addSubview:clickBtn];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(takeUp)];
        [self addGestureRecognizer:tap];
    }
    return self;
}


- (void)tapCover:(UITapGestureRecognizer *)tap{
    self.selectTitle(self.cate);
}

- (void)tapMoreCover:(UITapGestureRecognizer *)tap{
//    self.selectTitle(self.cate);
}

- (void)takeUp {
    self.dismiss();
}

@end
